package cn.ekuma.epos.datalogic.define.dao.crm;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.datalogic.define.dao.shard.PeopleEntityDAOHelper;
import cn.ekuma.epos.db.table.crm.I_CustomerPeople;
import cn.ekuma.epos.db.table.shard.I_PeopleEntityTable;

import com.openbravo.bean.Customer;
import com.openbravo.bean.crm.CustomerPeople;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class CustomerPeopleDAO extends ModifiedLogDAO<CustomerPeople>{

    public CustomerPeopleDAO(I_Session s) {
        super(s);
    }

	@Override
	public TableDefinition getTable() {
		TableDefinition table=PeopleEntityDAOHelper.getTable(s, "CUSTOMER_PEOPLE");
		table.addField( new Field(I_CustomerPeople.CUSTOMERID,Datas.STRING,Formats.STRING,Customer.class));
		table.addField( new Field(I_CustomerPeople.DEPARTMENT,Datas.STRING,Formats.STRING));
		table.addField( new Field(I_CustomerPeople.POSITION,Datas.STRING,Formats.STRING));
		table.addField( new Field(I_CustomerPeople.MEMO,Datas.STRING,Formats.STRING));
		table.addField( new Field(I_CustomerPeople.CREATEDATE,Datas.TIMESTAMP,Formats.TIMESTAMP));
		return table;
	}

	@Override
	public void writeInsertValues(DataWrite dp, CustomerPeople obj)
			throws BasicException {
		PeopleEntityDAOHelper.writeInsertValues(dp, obj, 1);
		dp.setString(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+1, obj.getCustomerId());
		dp.setString(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+2, obj.getDepartment());
		dp.setString(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+3, obj.getPosition());
		dp.setString(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+4, obj.getMemo());
		dp.setTimestamp(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+5, obj.getCreateDate());
	}

	@Override
	public Class getSuportClass() {
		return CustomerPeople.class;
	}

	@Override
	public CustomerPeople readValues(DataRead dr, CustomerPeople obj)
			throws BasicException {
		if(obj==null)
			obj=new CustomerPeople();
		PeopleEntityDAOHelper.readValues(dr, obj, 1);
		obj.setCustomerId(dr.getString(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+1));
		obj.setDepartment(dr.getString(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+2));
		obj.setPosition(dr.getString(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+3));
		obj.setMemo(dr.getString(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+4));
		obj.setCreateDate(dr.getTimestamp(I_PeopleEntityTable.PEOPLE_COLUMN_COUNT+5));
		return obj;
	}
}
